package com.yxlgateway.config;

import cn.dev33.satoken.interceptor.SaRouteInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author: yxl
 * @since: 2022-03-19
 **/
@Configuration
public class MySaTokenConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SaRouteInterceptor((request, response, handler) -> {
            SaRouter.notMatch("/user/login").match("/user/**").check(r->StpUtil.checkLogin());
            SaRouter.notMatch("/manager/login").check(r->StpUtil.checkLogin());
            SaRouter.match("/menus/**").check(r->StpUtil.checkLogin());
        })).addPathPatterns("/api/**");
    }
}
